<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" isELIgnored="false" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ include file="/include/header.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title><s:text name ="diffprice.tile"/></title>
<link href="<%=request.getContextPath() %>/fare/css/base.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/datePicker/WdatePicker.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/lib/ligerUI/js/ligerui.min.js"></script>
<link href="<%=request.getContextPath() %>/fare/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="<%=request.getContextPath() %>/fare/lib/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/jsFile/multiblepicker.js"></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/json2.js'></script>

<link rev="stylesheet" media="all" href="<%=request.getContextPath() %>/fare/css/form_style.css" type="text/css" rel="stylesheet"/>
<script type="text/javascript" src="<%=request.getContextPath()%>/jsFile/fdc.js"></script>
<link href='<%=request.getContextPath()%>/fare/js/cityquery/cityquery.css' rel="stylesheet" type="text/css" />
<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/citylist.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/querycity.js'></script>
<!-- 圆角文本框 -->
<link href="<%=request.getContextPath() %>/fare/css/htc/htc.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/grid.css"/>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/public.css"/>
<script type="text/javascript"
	src="<%=request.getContextPath() %>/jsFile/FDCCrawl/js/FDCCrawl.js">
</script>	
<script type="text/javascript"
	src="<%=request.getContextPath() %>/jsFile/wait/js/wait.js"></script>	
<style type="text/css">
        .l-case-title{font-weight:bold; margin-top:20px;margin-bottom:20px;}
        .l-taskbar {display: none;}
        .form_list td{
        	text-align: center;
        }
</style>
<script type="text/javascript">
$(function(){
	
	
	$('#depCity').querycity({'data':citysFlight,'tabs':labelFromcity});
	$('#arrCity').querycity({'data':citysFlight,'tabs':labelFromcity});
	$("#depCity").css({color:'black'});
	$("#arrCity").css({color:'black'});
	if($('#flightStartDate').val()==''){
		$('#flightStartDate').val(futureDate(0));
	}
	if($('#flightEndDate').val()==''){
		$('#flightEndDate').val(futureDate(7));
	}
	
 	$(".flightLine").live("click",function(){
 		var searchDepartureAirport = $(this).attr("id").split("_")[0];
 		var searchArrivalAirport = $(this).attr("id").split("_")[1];
 		var searchDepartureTime = $(this).attr("id").split("_")[2];
 		var searchArrivalTime = $("#flightEndDate").val();
 		var url = 'http://flight.qunar.com/site/oneway_list.htm?searchDepartureAirport='+searchDepartureAirport
 					+'&searchArrivalAirport='+searchArrivalAirport +'&searchDepartureTime='+searchDepartureTime+'&searchArrivalTime='+formatDate(searchDepartureTime,3)+
 				'&nextNDays=0&startSearch=true&from=qunarindex';
 		$(this).attr("href",url);
	});
	
	$("#depCity").css({color:"black"});
	$("#arrCity").css({color:"black"});
	
})
function formatDate(dateStr,N){
	var date = StringToDate(dateStr);
	return futureDate(date,N);
}

function StringToDate(DateStr)   
{    
   
    var converted = Date.parse(DateStr);   
    var myDate = new Date(converted);   
    if (isNaN(myDate))   
    {    
        //var delimCahar = DateStr.indexOf('/')!=-1?'/':'-';   
        var arys= DateStr.split('-');   
        myDate = new Date(arys[0],--arys[1],arys[2]);   
    }   
    return myDate;   
}
function futureDate(date,N){
	 var future = new Date(date.getTime()+N*24*60*60*1000);
	    var year = future.getFullYear();
	    var month = future.getMonth() + 1;
	    var day = future.getDate();
	    
	    var today = year + "-";       
	    if(month < 10)
	        today += "0";       
	    today += month + "-";       
	    if(day < 10)
	        today += "0";           
	    today += day;   
	    return(today); 
}
function futureDate(N){ 
    var now = new Date();
    var future = new Date(now.getTime()+N*24*60*60*1000);
    var year = future.getFullYear();
    var month = future.getMonth() + 1;
    var day = future.getDate();
    
    var today = year + "-";       
    if(month < 10)
        today += "0";       
    today += month + "-";       
    if(day < 10)
        today += "0";           
    today += day;       
    return(today); 
} 

/**
 * 根据毫秒返回日期
 */
function getDate(dateTime){ 
  
    var future = new Date(dateTime);
    var year = future.getFullYear();
    var month = future.getMonth() + 1;
    var day = future.getDate();
    
    var today = year + "-";       
    if(month < 10)
        today += "0";       
    today += month + "-";       
    if(day < 10)
        today += "0";           
    today += day;       
    return(today); 
} 

function checkJspForm(){

	if(!checkForm()){
		return false;
	}
	setTimeout(function(){loadAndDisplayData('lineSpreadMonitorAction!queryData.action');},1);
}
function checkForm(){
	var alertLocalSel=document.getElementById("share.showDifferent2").value;
	if($('#depCity').val()=='中文/拼音' && $('#arrCity').val()=='中文/拼音' && $('#arrCity').val()=="City name" && $('#depCity').val()=='City name'){
		alert(alertLocalSel);
		return false;
	}
	if($('#depCity').val()== $('#arrCity').val()){
		alert(alertLocalSel);
		return false;
	}
	if($('#depCity').val()=='中文/拼音'){
		$('#depCity').val('');
		$('#depCityCode').val('');
	}
	if($('#arrCity').val()=='中文/拼音'){
		$('#arrCity').val('');
		$('#arrCityCode').val('');
	}
	if($('#depCity').val()=='City name'){
		$('#depCity').val('');
		$('#depCityCode').val('');
	}
	if($('#arrCity').val()=='City name'){
		$('#arrCity').val('');
		$('#arrCityCode').val('');
	}
	return true;
}
function loadAndDisplayData(url){
	var searchNoData=document.getElementById("diffprice.searchFail");
		$("#channel").attr("action", url);
		FDCWait.show();
	$.ajax({
		   type: "POST",
		   url: url,
		   data: $("#myForm").serialize(),
		   success: function(jsonData){
			   FDCWait.hide();
			   if(jsonData.jsonSize == '0'){
				   alert(searchNoData);
			   }else{
				   $("#tableBody").empty(); 
				   createTable(jsonData.jsonString);
			   }
		   }
		});
	}
/**
*   Usage:  CurrencyFormatted(12345.678);
*   result: 12345.68
**/
function CurrencyFormatted(amount) {
    var i = parseFloat(amount);
    if(isNaN(i)) { i = 0.00; }
    var minus = '';
    if(i < 0) { minus = '-'; }
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i);
    if(s.indexOf('.') < 0) { s += '.00'; }
    if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
    s = minus + s;
    return s;
}
 

/* function createTable(jsonData){
		 var tableStr = '';
		for(var line in jsonData){//遍历json对象的每个key/value对,p为key
			var rowSpan = jsonData[line].length;
			var data = jsonData[line];
		//获得每条航线的航班数量
		
		
		
		for(var i=0;i<data.length;i++){
			tableStr += "<tr>";
			var flightLine = data[i].fromCityName +"-"+ data[i].toCityName;
			tableStr += '<td class="line" style="text-align: center">'+(i+1)+'</td>';
			if(i==0){
				tableStr += '<td class="line" rowspan="'+rowSpan+'" style="text-align: center">'+'<a href="" target="_blank" class="flightLine" id='+flightLine+'>'+flightLine+'</a>'+'</td>';
			}
			
			tableStr += '<td class="line" style="text-align: center">'+data[i].flightDateStr+'</td>';
			tableStr += '<td class="line" style="text-align: center">'+data[i].flightNo+'</td>';
			if(data[i].flightType == '0' || data[i].flightType == 0){
				tableStr += '<td class="line" style="text-align: center">'+'单程'+'</td>';
			}
			tableStr += '<td class="line" style="text-align: center">'+'去哪儿'+'</td>';
			if(data[i].qunaerAgentName == null){
				tableStr += '<td class="line" style="text-align: center"></td>';		
			}else{
				tableStr += '<td class="line" style="text-align: center">'+data[i].qunaerAgentName+'</td>';		
			}
		
			tableStr += '<td class="line" style="text-align: center">'+data[i].price+'</td>';
			
			if(data[i].qunaerPrice == null){
				tableStr += '<td class="line" style="text-align: center"></td>';
			}else{
				tableStr += '<td class="line" style="text-align: center">'+data[i].qunaerPrice+'</td>';
			}
			
			if(data[i].qunaerSpreadAmount == null){
				tableStr += '<td class="line" style="text-align: center"></td>';
			}else{
				tableStr += '<td class="line" style="text-align: center">'+data[i].qunaerSpreadAmount+'</td>';
			}
			
			if(data[i].qunaerSpread == null){
				tableStr += '<td class="line" style="text-align: center"></td>';	
			}else{
				tableStr += '<td class="line" style="text-align: center">'+CurrencyFormatted(data[i].qunaerSpread)+'%</td>';	
			}
			
			if(getDate(data[i].grabTime) == null){
				tableStr += '<td class="line" style="text-align: center"></td>';	
			}else{
				tableStr += '<td class="line" style="text-align: center">'+data[i].grabDateStr+'</td>';	
			}
					
			tableStr += '</tr>';	
		}
		}
		$("#tableBody").append(tableStr); 
		
		
		
} */

function createTable(jsonData){
	 var tableStr = '';
	 var channelName = $("#channel").find("option:selected").text();
	for(var line in jsonData){//遍历json对象的每个key/value对,p为key
		var rowSpan = jsonData[line].length;
		var data = jsonData[line];
	//获得每条航线的航班数量
	for(var i=0;i<data.length;i++){
		tableStr += "<tr>";
		var flightLine = data[i].fromCityName +"-"+ data[i].toCityName;
		var flightLineAndDate = data[i].fromCityName +"_"+ data[i].toCityName+"_"+data[i].flightDateStr;
		tableStr += '<td class="line" style="text-align: center">'+(i+1)+'</td>';
		if(i==0){
			tableStr += '<td class="line" rowspan="'+rowSpan+'" style="text-align: center">'
			+'<a href="" target="_blank" class="flightLine" id='+flightLineAndDate+'>'+flightLine+'</a>'+'</td>';
		}
		
		tableStr += '<td class="line" style="text-align: center">'+data[i].flightDateStr+'</td>';
		tableStr += '<td class="line" style="text-align: center">'+data[i].flightNo+'</td>';
		if(data[i].flightType == '0' || data[i].flightType == 0){
			tableStr += '<td class="line" style="text-align: center">'+'<s:text name ="diffprice.oneWay"/>'+'</td>';
		}
		tableStr += '<td class="line" style="text-align: center">'+channelName+'</td>';
		if(data[i].qunaerAgentName == null){
			tableStr += '<td class="line" style="text-align: center"></td>';		
		}else{
			tableStr += '<td class="line" style="text-align: center">'+data[i].qunaerAgentName+'</td>';		
		}
	
		tableStr += '<td class="line" style="text-align: center">'+(data[i].price<0 ? '--' : data[i].price)+'</td>';
		
		if(data[i].qunaerPrice == null){
			tableStr += '<td class="line" style="text-align: center">--</td>';
		}else{
			tableStr += '<td class="line" style="text-align: center">'+data[i].qunaerPrice+'</td>';
		}
		
		if(data[i].qunaerSpreadAmount == null){
			tableStr += '<td class="line" style="text-align: center">--</td>';
		}else{
			tableStr += '<td class="line" style="text-align: center">'+data[i].qunaerSpreadAmount+'</td>';
		}
		
		if(data[i].qunaerSpread == null){
			tableStr += '<td class="line" style="text-align: center">--</td>';	
		}else{
			tableStr += '<td class="line" style="text-align: center">'+CurrencyFormatted(data[i].qunaerSpread)+'%</td>';	
		}
		
		if(getDate(data[i].grabTime) == null){
			tableStr += '<td class="line" style="text-align: center"></td>';	
		}else{
			tableStr += '<td class="line" style="text-align: center">'+data[i].grabDateStr+'</td>';	
		}
				
		tableStr += '</tr>';	
	}
	}
	$("#tableBody").append(tableStr); 
	
	
	
}
</script>


	
</head>

<body>
	<%@ include file="/include/home/home_header.jsp" %>
<jsp:include page="/pages/system/feedback/feedback.jsp" ></jsp:include>
	<div class="main main_max minhgt450">
		<div class="sideBar">
			<div class="box">
				<div class="location"><s:text name ="share.currentL"/>： <s:text name ="channelAnalysis"/> &gt; <s:text name="fareDifferenceAnalysis"/></div>
			</div>
		</div>
		<div class="form_table_tltle"><s:text name ="forms.query"/></div>
		<form id="myForm" name="channelForm" method="post"
			action="lowestPriceQueryAction!analyse.action">
			<input type="hidden" id="share.showDifferent2" value="<s:text name="share.showDifferent2"/>" />
			<input type="hidden" id="diffprice.searchFail" value="<s:text name ="diffprice.searchFail"/>">
			<table cellSpacing=0 cellPadding=0 width="100%" border=0
				class="form_table">
				<TR>
					<TD height="26" class="left" style="text-align: left"><s:text name ="forms.airlines"/>：</TD>
					<TD>
					<input type="hidden" name="carrier" id="carrier" value="${carrier}"/>
					<select name="carrierSelect" style="width: 150px;" id="carrierSelect" disabled="disabled">
							<c:choose>
								<c:when test="${sourceLists == null}">
								</c:when>
								<c:otherwise>
									<c:forEach var="item" items="${sourceLists }">
										<option value="${item.hbaseKey}"
											<c:if test="${item.hbaseKey==carrier}">
												selected='selected'
											 </c:if>
										>
										${item.name}
										</option>
									</c:forEach>
								</c:otherwise>
							</c:choose>
					</select><font color="red">*</font></TD>
					<TD class="left" style="text-align: left"></TD>
					<TD></TD>
				</TR>

				<TR>
					<TD width="120" height="26" class="left" style="text-align: left"><s:text name ="diffprice.flightLines"/>：</TD>
					<TD>
					
					<c:if test="${language=='en_US'}">
						<jsp:include page="/inc/flightSelect_en_Us.jsp">
							<jsp:param value="${fromCity}" name="fromCity"></jsp:param>
							<jsp:param value="${fromCityCode}" name="fromCityCode"></jsp:param>
							<jsp:param value="${toCity}" name="toCity"></jsp:param>
							<jsp:param value="${toCityCode}" name="toCityCode"></jsp:param>
						</jsp:include>
		   			</c:if>
				 	<c:if test="${language=='zh_CN' or language=='other'}">
				 		<jsp:include page="/inc/flightSelect.jsp">
					 		<jsp:param value="${fromCity}" name="fromCity"></jsp:param>
							<jsp:param value="${fromCityCode}" name="fromCityCode"></jsp:param>
							<jsp:param value="${toCity}" name="toCity"></jsp:param>
							<jsp:param value="${toCityCode}" name="toCityCode"></jsp:param>
						</jsp:include>
					</c:if>
						<%-- <jsp:include page="../inc/flightSelect.jsp">
							<jsp:param value="${fromCity}" name="fromCity"/>
							<jsp:param value="${fromCityCode}" name="fromCityCode"/>
							<jsp:param value="${toCity}" name="toCity"/>
							<jsp:param value="${toCityCode}" name="toCityCode"/>
						</jsp:include>  --%>
					</TD>
					<TD width="120" class="left" style="text-align: left"></TD>
					<TD></TD>
				</TR>


				<TR>
					<TD height="26" class="left" style="text-align: left">
					<input	id="" name="flightDate" checked="chencked" type="radio" value="1"/><s:text name ="share.flightDate"/>：
					</TD>
					<TD>
					<input  name="flightStartDate" type="text" id="flightStartDate" style="width: 100px"
						onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',minDate: '%y-%M-%d',maxDate:'${maxDate}',lang:'<s:i18n name='forms'><s:text name='forms.locale'></s:text></s:i18n>'});"></input>
							<span>~</span> 
						<input name="flightEndDate" type="text" id="flightEndDate" style="width: 100px"
							onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd',minDate: '%y-%M-%d',maxDate:'${maxDate}',lang:'<s:i18n name='forms'><s:text name='forms.locale'></s:text></s:i18n>'});"></input>
								<span style="color: #ff0000">*</span></TD>
					<TD class="left" style="text-align: left"><s:text name ="share.channel"/></>:</TD>
					<TD><select name="channel" id="channel">
							<option value="00001"><s:text name ="share.taobao"/></option> 
							<option value="00002" selected="selected"><s:text name ="share.qunar"/></option>
					</select></TD>
				</TR>
				<TR>

					<TD class="left" style="text-align: center;" colspan="4">
					<input type="button" onclick="javascript:checkJspForm();" value=""	class="<s:i18n name='forms'><s:text name='forms.btn01'></s:text></s:i18n>" id="Submit2" /> 
					<input type="reset" onclick=""	value="" class="<s:i18n name='forms'><s:text name='forms.btn02'></s:text></s:i18n>" id="Submit222" />
					</TD>
				</TR>

			</TABLE>
		</form>
		<p></p>
		<div style="display: none">
			<input id="text" type="text" value="<s:property value="totalPage"/>">
		</div>


		<div id='priceTable'
			style="margin: 5px 0 0 5px; auto; text-align: left;"></div>

		<br>
			<div id="norecord" style="margin-bottom: 1px; display: none"><s:text name ="diffprice.failsearch"></s:text></div>

			<div class="form_table_tltle"><s:text name ="forms.queryResults"/></div>
			<table width="0" border="0" cellspacing="0" cellpadding="0"
				class="form_list">
				<tr class="title">
					<td style="text-align: center; width: 38px;"><s:text name ="share.index"/></td>
					<td style="text-align: center; width: 100px;"><s:text name ="share.flightLine"/></td>
					<td style="text-align: center; width: 85px;"><s:text name ="diffprice.date"/></td>
					<td style="text-align: center; width: 115px;"><s:text name ="share.flighNumber"/></td>
					<td style="text-align: center; width: 35px;"><s:text name ="diffprice.flightStyle"/></td>
					<td style="text-align: center; width: 85px;"><s:text name ="share.channel"/></td>
					<td style="text-align: center; width: 50px;"><s:text name ="forms.agent"/></td>
					<td style="text-align: center; width: 85px;"><s:text name ="forms.B2C"></s:text></td>
					<td style="text-align: center; width: 85px;"><s:text name ="diffprice.agencyPrice"></s:text></td>
					<td style="text-align: center; width: 85px;"><s:text name ="forms.spread"/></td>
					<td style="text-align: center; width: 85px;"><s:text name ="forms.spreadAment"/></td>
					<td style="text-align: center; width: 85px;"><s:text name ="share.grabDate"/></td>
					
				</tr>
				
				<tbody id="tableBody">
				</tbody>

			</table>

	<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>

</div>
<br></br>  <br></br>  <br></br>  <br></br>  <br></br>
<%@ include file="/include/home/home_footer.jsp" %>  
</body>
</html>